package com.zzzzzz.account.model;

import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.GraphTraversal;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;

import com.zzzzzz.topic.model.LikeOutgoingTraversalBuilder;
import com.zzzzzz.topic.model.TopicGraph;

@NodeEntity
public class UserGraph {
	
	@GraphId Long id;

	@Indexed
	private String userId;

	public UserGraph() {
		
	}

	public UserGraph(String userId) {
		this.userId = userId;
	}

    @RelatedTo(type = "FOLLOW", elementClass = UserGraph.class, direction = Direction.OUTGOING)
    private Set<UserGraph> following;

    @RelatedTo(type = "LIKE", elementClass = TopicGraph.class, direction = Direction.OUTGOING)
    private Set<TopicGraph> likes;
	
    @GraphTraversal(traversal = FollowingTraversalBuilder.class, elementClass = UserGraph.class)
    private Iterable<UserGraph> allFollowing;

    @GraphTraversal(traversal = FollowersTraversalBuilder.class, elementClass = UserGraph.class)
    private Iterable<UserGraph> allFollowers;
    
    @GraphTraversal(traversal = LikeOutgoingTraversalBuilder.class, elementClass = TopicGraph.class)
    private Iterable<TopicGraph> allTopicsWhichUserLike;

    public void addFollwing(UserGraph userGraph) {
        this.following.add(userGraph);
    }
    
    public void addLike(TopicGraph topicGraph) {
        this.likes.add(topicGraph);
    }

    public void addShare(TopicGraph topicGraph) {
        this.likes.add(topicGraph);
    }
	
	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Set<UserGraph> getFollowing() {
		return following;
	}

	public void setFollowing(Set<UserGraph> following) {
		this.following = following;
	}

	public Iterable<UserGraph> getAllFollowing() {
		return allFollowing;
	}

	public void setAllFollowing(Iterable<UserGraph> allFollowing) {
		this.allFollowing = allFollowing;
	}

	public Iterable<UserGraph> getAllFollowers() {
		return allFollowers;
	}

	public void setAllFollowers(Iterable<UserGraph> allFollowers) {
		this.allFollowers = allFollowers;
	}

	public Iterable<TopicGraph> getAllTopicsWhichUserLike() {
		return allTopicsWhichUserLike;
	}

	public void setAllTopicsWhichUserLike(
			Iterable<TopicGraph> allTopicsWhichUserLike) {
		this.allTopicsWhichUserLike = allTopicsWhichUserLike;
	}

	public Set<TopicGraph> getLikes() {
		return likes;
	}

	public void setLikes(Set<TopicGraph> likes) {
		this.likes = likes;
	}

}
